"""
@author: tian-yan-tian-ge
@file: 2023.11.24tree命令.py
@time: 2023/11/25 20:04
"""
import os


def tree(directory, max_depth=None, depth=0):
    if max_depth is not None and depth >= max_depth:
        return

    for root, dirs, files in os.walk(directory):
        for name in dirs:
            print(' ' * depth + '- ' + os.path.join(root, name))
        for name in files:
            print(' ' * (depth + 2) + '- ' + os.path.join(root, name))
        if max_depth is not None and depth >= max_depth - 1:
            return


tree('/path/to/directory')
